import json
from typing import Any

import robot_pb2


def _json_response(code, msg, data) -> robot_pb2.Response:
    resp_str = json.dumps({
        "code": code,
        "msg": msg,
        "data": data
    })
    return robot_pb2.Response(data=resp_str)


def json_success_response(data: Any = "success") -> robot_pb2.Response:
    if data is None:
        data = "success"
    return _json_response(0, "", data)


def json_error_response(msg, code=-1) -> robot_pb2.Response:
    return _json_response(code, msg, "")


if __name__ == '__main__':
    a = json_success_response("哈哈哈")
    print(type(a))
